﻿@using QH.JobBack.Model;
@{
    List<Admininfo> list = new List<Admininfo>();
    var addisupdate = 0;
    if (ViewBag.list != null)
    {
        list = ViewBag.list;
        addisupdate = 1;
    }
}
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
    <meta name="renderer" content="webkit">
    <!--国产浏览器高速模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="穷在闹市" />
    <!-- 作者 -->
    <meta name="revised" content="穷在闹市.v3, 2019/05/01" />
    <!-- 定义页面的最新版本 -->
    <meta name="description" content="网站简介" />
    <!-- 网站简介 -->
    <meta name="keywords" content="搜索关键字，以半角英文逗号隔开" />
    <title>穷在闹市出品</title>

    <!-- 公共样式 开始 -->
    <link rel="stylesheet" type="text/css" href="../../css/base.css">
    <link rel="stylesheet" type="text/css" href="../../fonts/iconfont.css">
    <script type="text/javascript" src="../../framework/jquery-1.11.3.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <script src="../../framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
    <!-- 公共样式 结束 -->

    <style>

        .layui-form {
            margin-right: 30%;
        }
    </style>

</head>

<body>
    <form id="addForm" class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">管理员名</label>
            <div class="layui-input-inline shortInput">
                @if (ViewBag.list != null)
                {
                    foreach (var item in list)
                    {
                        <input type="text" id="loginName" name="loginName" value="@item.AdminName" required  autocomplete="off" class="layui-input">
                    }
                }
                else
                {
                    <input type="text" id="loginName" name="loginName" value="" required   autocomplete="off" class="layui-input">
                }
                
            </div>
        </div>
        @if (addisupdate==0)
        {
            <div class="layui-form-item">
                <label class="layui-form-label">登录密码</label>
                <div class="layui-input-inline shortInput">
                    <input type="password" id="password" name="password" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline shortInput">
                    <input type="password" id="password2" name="password2" autocomplete="off" class="layui-input">
                </div>
            </div>
        }
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline shortInput">
                @if (ViewBag.list != null)
                {
                    foreach (var item in list)
                    {
                        <input type="text" id="phone" name="phone" value="@item.Phone" required lay-verify="required|phone" placeholder="" autocomplete="off" class="layui-input">
                    }
                }
                else
                {
                    <input type="text" id="phone" name="phone" required lay-verify="required|phone" placeholder="例：13000000000" autocomplete="off" class="layui-input">
                }
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline shortInput">
                @if (ViewBag.list != null)
                {
                    foreach (var item in list)
                    {
                        <input type="text" value="@item.Email" id="title" name="title" autocomplete="off" class="layui-input">
                    }
                }
                else
                {

                    <input type="text" id="title" name="title" autocomplete="off" class="layui-input">
                }
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否开通</label>
            <div class="layui-input-block">
                @if (ViewBag.list != null)
                {
                    foreach (var item in list)
                    {
                        <input type="checkbox" name="star" lay-skin="switch" lay-filter="switchTest" lay-text="启用|禁用" checked="@item.STATUS" />
                    }
                }
                else
                {

                    <input type="checkbox" name="star" lay-skin="switch" lay-filter="switchTest" lay-text="启用|禁用" checked />
                }
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                @if (ViewBag.list != null)
                {
                    foreach (var item in list)
                    {
                        <input type="checkbox" name="Sex" lay-skin="switch" lay-filter="switchTest" lay-text="男|女" checked="@item.Sex" />
                    }
                }
                else
                {

                    <input type="checkbox" name="Sex" lay-skin="switch" lay-filter="switchTest" lay-text="男|女" checked />
                }
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <div class="layui-btn add-Admins" lay-submit lay-filter="submitBut">立即提交</div>
                <button type="reset" id="AdminId" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <!-- 三级省市 插件 -->
    <script src="../../framework/area.js"></script>
    <script src="../../framework/province.js"></script>
</body>
</html>
<script>
    $(".add-Admins").click(function () {
        if (@addisupdate== 0) {
            //添加
            var data = {};
            data.AdminName = $("#loginName").val();
            data.Phone = $("#phone").val();
            data.AdminPwd = $("#password").val();
            data.Email = $("#title").val();
            data.STATUS = $("input[name='star']").prop('checked');
            data.Sex = $("input[name='Sex']").prop('checked');
            $.ajax({
                type: "post",
                url: "/Admin/AddAdmininfo",
                data: data,
                success: function (json) {
                    if (json.Success) {
                        layer.alert('添加成功！', {
                            title: '提示框',
                            icon: 1,
                        }, function () {
                            location.href = "/Admin/AdminList";
                        });

                    } else {
                        layer.alert('添加失败！', {
                            title: '提示框',
                            icon: 0,
                        });
                        layer.close(MenuSection);
                    }
                }
            });
        } else {
            var data = {};
            data.AdminId = $("#AdminId").val();
            data.AdminName = $("#loginName").val();
            data.Phone = $("#phone").val();
            data.Email = $("#title").val();
            data.STATUS = $("input[name='star']").prop('checked');
            data.Sex = $("input[name='Sex']").prop('checked');
            $.ajax({
                type: "post",
                url: "/Admin/UpdateAdmininfo",
                data: data,
                success: function (json) {
                    if (json.Success) {
                        layer.alert('修改成功！', {
                            title: '提示框',
                            icon: 1,
                        }, function () {
                            location.href = "/Admin/AdminList";
                        });

                    } else {
                        layer.alert('修改失败！', {
                            title: '提示框',
                            icon: 0,
                        });
                        layer.close(MenuSection);
                    }
                }
            });
        }
    });

</script>